package HibernateUtil;




import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;



 

public class HibernateUtil {
	
	private static SessionFactory buildSessionFactory() {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			//new Configuration().configure().buildSessionFactory()
			Configuration cfg = new Configuration();
		    //.addResource("../demo_hibernate_2/src/Data/TblMoto.hbm.xml");
			SessionFactory sessionFactory = cfg.configure().buildSessionFactory();
			return sessionFactory;
		} catch (Throwable ex) {
			// Make sure you log the exception, as it might be swallowed
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}
 
	public static SessionFactory getSessionFactory() {
		return buildSessionFactory();
	}
 
	public static void shutdown() {
		// Close caches and connection pool
		try {
			getSessionFactory().close();
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
}
